﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace LotteCinema
{
    public partial class LichChieuPhim : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string kq = "";
            DataTable thoigian = CProvider.Docbang("exec viewLichChieuPhim_ThoiGian '" + Request["maphim"].ToString() + "', '" + Request["marap"].ToString() + "'");
            if (thoigian.Rows.Count > 0)
            {
                for (int i = 0; i < thoigian.Rows.Count; i++)
                {
                    int dayOfWeek = (int)Convert.ToDateTime(thoigian.Rows[i][0].ToString()).DayOfWeek;
                    string weekendday = Convert.ToDateTime(thoigian.Rows[i][0].ToString()).DayOfWeek.ToString();
                    kq += "<h5>" + (dayOfWeek == 6 ? "Chủ Nhật" : "Thứ " + (dayOfWeek + 1).ToString()) + ",&nbsp;" + Convert.ToDateTime(thoigian.Rows[i][0].ToString()).ToShortDateString() + "</h5>";
                    string ngaychieu = (dayOfWeek == 6 ? "Chủ Nhật" : "Thứ " + (dayOfWeek + 1).ToString()) + ",&nbsp;" + Convert.ToDateTime(thoigian.Rows[i][0].ToString()).ToShortDateString();
                    DataTable suatchieu = CProvider.Docbang("set dateformat dmy exec viewLichChieuPhim_SuatChieu '" + Convert.ToDateTime(thoigian.Rows[i][0].ToString()).ToShortDateString() + "', '" + Request["maphim"].ToString() + "', '" + Request["marap"].ToString() + "'");
                    if (suatchieu.Rows.Count > 0)
                    {
                        for (int j = 0; j < suatchieu.Rows.Count; j++)
                        {
                            string giochieu = string.Format("{0:HH}", suatchieu.Rows[j][1].ToString()).Substring(0, 5);
                            string intgiochieu = int.Parse(string.Format("{0:HH}", suatchieu.Rows[j][1].ToString()).Substring(0, 2)).ToString();
                            kq += "<a href=\"?step=2&weekendday=" + weekendday + "&ngaychieu=" + ngaychieu + "&giochieu=" + giochieu + "&intgiochieu=" + intgiochieu + "&phongchieu=" + suatchieu.Rows[j][2] + "&masc=" + suatchieu.Rows[j][0] + "&malcp=" + suatchieu.Rows[j][3] + "\" class=\"showtime_mov_hour btnShowtime\">" + giochieu + "</a>&nbsp;&nbsp;&nbsp;";

                        }
                    }
                }
            }
            Response.Write(kq);
        }
    }
}